home *** CD-ROM | disk | FTP | other *** search
- /* area.c 6/2/84
- Telephone area code search program
- (C) 1984 Martin Smith
- Compuserve 72155,1214
- 310 Cinnamon Oak Lane (713) 661-1241 [Office]
- Houston, Texas 77079 (713) 464-6737 [Home]
-
- Find area codes by entering an area code or state name on the
- command line. Multiple codes, names are permitted up to 20,
- the limit set forth for C86 Computer Innovations(tm) compiler,
- although your compiler may be different.
- Program written for IBM-PC with PC-DOS 2.0, but no machine-specific
- code is involved, other than the GETTIME routine.
-
- This code has been modified on 2/1/85 by the Device Driver to
- (1) speed it up, (2) allow multiple names to be found, (3) add time
- zones, (4) add foreign countries, (5) add new area codes.
-
- The table is near the top of this file to make it easier to maintain.
- Area codes don't change much, but just this year in Houston our
- area code was broken off from the surrounding area.
- The format of the table is simple, so adding cities to the city list
- or even new states or regions won't upset the program if a few easy
- rules are followed:
-
- 1) The table format is one array of string pointers.
- 2) A state name consists of a two character postal abbreviation,
- like ca for California, and then the actual name,
- a) All data on this line is lowercase. A multiple word name,
- like New Jersey, would be entered as "njnew*jersey" , .
- This prevents argv from making two arguments out of the name.
- 3) An area code is the three digit code, followed by whatever text.
- a) As many area codes, cities as you want are ok.
- b) Note the program depends on a state name not beginning with
- a number. When a numeric code is searched and found, the
- program goes back to the first non-numeric for the state name.
- 4) All entries need to be enclosed in quotes (") and followed by a
- comma.
- 5) Countries have the same form as states.
- 6) Time zone follow the state name as (+n) for n hours after Eastern,
- (-n) for n hours before Eastern, and (\t..) to add an extra 1/2
- hour.
- */
-
- #include "stdio.h"
- #include "ctype.h"
- #include "dos.h"
- int tme[10]; /* time date array */
- areacode(s,x)
- char *s;
- int x;
- {
- unsigned strlen();
-
- static char *area[] =
-
- {
- "alalabama(-1)", "205 All pts",
- "akalaska(-5)", "907 All pts",
- "azarizona(-2)", "602 All pts",
- "ararkansas(-1)", "501 All pts",
- "cacalifornia(-3)" ,
- "209 Fresno" , "213 Los Angeles" , "408 San Jose" ,
- "415 San Francisco" , "619 San Diego" , "707 Santa Rosa" ,
- "714 Orange" , "805 Bakersfield" , "916 Sacramento" ,
- "cncanada - pacific(-3)" ,
- "604 British Columbia:Vancouver" ,
- "cncanada - mountain(-2)" ,
- "306 Saskatchewan:" ,
- "403 Alberta: Calgary, Edmonton" ,
- "cncanada - central(-1)" ,
- "204 Manitoba:" ,
- "cncanada - eastern(0)" ,
- "416 Ontario: Toronto, Mississauga" ,
- "418 Quebec: Quebec" ,
- "514 Quebec: Montreal" ,
- "519 Ontario: London" ,
- "613 Ontario: Ottawa" ,
- "705 West Ontario" ,
- "807 East Ontario" ,
- "819 NW Quebec" ,
- "cncanada - atlantic(+1)" ,
- "709 Newfoundland:" ,
- "506 New Brunswick: Costa Rica" ,
- "902 Nova Scotia & Prince Edward Island:" ,
- "cocolorado(-2)" , "303 All pts" ,
- "ctconnecticut(0)" , "203 All pts" ,
- "dedelaware(0)" , "302 All pts" ,
- "dcdistrict*of*columbia(0)" , "202 Washington" ,
- "flflorida(0)" ,
- "305 Miami, Key West, Ft. Lauderdale" ,
- "813 Ft. Myers, Winter Haven" , "904 Jacksonville" ,
- "gageorgia(0)" ,
- "404 Atlanta, Rome" , "912 Waycross" ,
- "hihawaii(-5)", "808 All pts" ,
- "ididaho(-2)", "208 All pts" ,
- "ilillinois(-1)" ,
- "217 Springfield" , "309 Peoria" , "312 Chicago, Aurora, Waukegan" ,
- "618 Alton, Mt. Vernon" , "815 Rockford" ,
- "inindiana(0)" ,
- "219 Gary, South Bend, Warsaw" ,
- "317 Indianapolis, Kokomo" , "812 Evansville" ,
- "iaiowa(-1)" ,
- "319 Dubuque" , "515 Des Moines" , "712 Council Bluffs" ,
- "kskansas(-1)" ,
- "316 Wichita, Dodge City" ,
- "913 Topeka, Lawrence, Manhattan, Salina" ,
- "kykentucky(0)" ,
- "502 Louisville, Frankfort, Paducah, Shelbyville" , "606 Winchester" ,
- "lalouisiana(-1)" ,
- "504 Baton Rouge, New Orleans" , "318 Lake Charles" ,
- "memaine(0)", "207 All pts" ,
- "mdmaryland(0)", "301 All pts" ,
- "mamassachusetts(0)" ,
- "413 Springfield" ,
- "617 Boston, New Bedford, Plymouth, Worchester" ,
- "mxmexico(+1)" ,
- "905 Mexico City" , "706 NW Mexico" ,
- "mimichigan(0)" ,
- "313 Detroit, Ann Arbor, Flint" ,
- "616 Battle Creek, Grand Rapids, Kalamazoo" ,
- "517 Lansing" , "906 Escanaba" ,
- "mnminnesota(-1)" ,
- "218 Duluth" , "612 Minneapolis, St. Paul" , "507 Rochester" ,
- "msmississippi(-1)", "601 All pts" ,
- "momissouri(-1)" ,
- "314 St. Louis, Cape Girardeau, Columbia, Fulton, Hannibal, \n\tJefferson City, Mexico, Poplar Bluff, Rolla" ,
- "417 Joplin, Springfield" ,
- "816 Belton, Independence, Kansas City, Marshall, St. Joseph, Sedalia" ,
- "mtmontana(-2)", "406 All pts" ,
- "nenebraska(-1)" ,
- "402 Omaha, Lincoln" , "308 North Platte" ,
- "nvnevada(-3)", "702 All pts" ,
- "nhnew*hampshire(0)", "603 All pts" ,
- "njnew*jersey(0)" ,
- "201 Newark, Hackensack, New Brunswick, Patterson" ,
- "609 Atlantic City, Camden, Trenton" ,
- "nmnew*mexico(-2)", "505 All pts" ,
- "nynew*york(0)" ,
- "212 New York City" , "315 Syracuse" , "518 Albany, Schenectady" ,
- "607 Binghamton" , "716 Buffalo, Niagara Falls, Rochester" ,
- "718 New York City" , "914 White Plains" ,
- "ncnorth*carolina(0)" ,
- "704 Charlotte, Salisbury" ,
- "919 Greenville, Raleigh, Winston-Salem" ,
- "ndnorth*dakota(-1)", "701 All pts" ,
- "ohohio(0)" ,
- "216 Akron, Cleveland, Youngstown" ,
- "419 Toledo" ,
- "513 Cincinnati, Dayton" , "614 Columbus" ,
- "okoklahoma(-1)" ,
- "405 Oklahoma City, Enid, Norman, Ponca City, Stillwater" ,
- "918 Tulsa, Bartlesville, McAlester, Muskogee" ,
- "ororegon(-3)", "503 All pts" ,
- "papennsylvania(0)" ,
- "215 Philadelphia, Allentown" ,
- "412 Pittsburgh" , "717 Harrisburg, Scranton" , "814 Erie" ,
- "prpuerto*rico(0)" ,
- "809 Anguilla, Antigua, Bahamas, Barbados, Bermuda, Cayman Islands, \n\tDominican Republic, Jamaica, St. Lucia, Trinidad" ,
- "rirhode*island(0)", "401 All pts" ,
- "scsouth*carolina(0)", "803 All pts" ,
- "sdsouth*dakota(-1)", "605 All pts" ,
- "tntennessee(-1)" ,
- "615 Nashville, Chattanooga" , "901 Memphis" ,
- "txtexas(-1)" ,
- "214 Dallas, Ennis, Greenville, Jefferson, Longview, Sherman, Tyler" ,
- "409 Bay City, Beaumont, Bryan, College Station, Galveston, Huntsville" ,
- "512 Austin, Brownsville, Corpus Christi, Del Rio, Eagle Pass, \n\tLaredo, McAllen, San Antonio, Victoria" ,
- "713 Houston, Baytown, Pasadena" ,
- "806 Amarillo, Dalhart, Lubbock" ,
- "817 Fort Worth, Denton, Temple, Waco, Wichita Falls" ,
- "915 Abilene, Alpine, Big Spring, El Paso, Midland, Odessa" ,
- "ututah(-2)", "801 All pts" ,
- "vtvermont(0)", "802 All pts" ,
- "vivirgin*islands(0)", "809 All pts" ,
- "vavirginia(0)" ,
- "703 Roanoke, Winchester" ,
- "804 Charlottesville, Newport News, Norfolk, Richmond" ,
- "wawashington(-3)" ,
- "206 Seattle, Olympia, Vancouver" , "509 Walla Walla" ,
- " wide area" , "800 All pts" ,
- "wvwest*virginia(0)", "304 All pts" ,
- "wiwisconsin(-1)" ,
- "414 Milwaukee, Green Bay, Racine" ,
- "608 Madison" , "715 Wausau" ,
- "wywyoming(-2)", "307 All pts" ,
- "--algeria(+6)" , "213 All",
- "--argintina(+2)" , "54- All",
- "--australia(+15)" , "61- Adelaide, Melbourne, Newcastle, South perth, Spring hill, Sydney",
- "--austria(+6)" , "43- Vienna",
- "--barbados(+1)" , "809 All",
- "--belgium(+6)" , "32- Brussels",
- "--bolivia(+1)" , "591 All",
- "--braddon(0)" , "616 All",
- "--brazil(+2)" , "55- All",
- "--cameroon(+6)" , "237 All",
- "--chile(+1)" , "056 All",
- "--columbia(0)" , "287 bogota",
- "--costa rica(-1)" , "506 All",
- "--cyprus(+7)" , "357 All",
- "--denmark(+6)" , "45- Copenhagen",
- "--egypt(+7)" , "20- All",
- "--el salvador(-1)" , "503 All",
- "--equador(+0)" , "593 Ecuador",
- "--ethiopia(+8)" , "251 All",
- "--finland(+7)" , "358 Helsinki",
- "--france(+6)" , "33- All",
- "--french antilles(+1)" , "596 All",
- "--french polyesia(-5)" , "589 All",
- "--fuji(+17)" , "679 All",
- "--gabon(+6)" , "241 All",
- "--germ dem. rep.(+6)" , "37- All",
- "--germ fed rep of(+6)" , "49- Duesseldorf, frankfurt, hamburg, hannover, muenchen, \n\tnberg, stuttart",
- "--greece(+7)" , "030 All",
- "--guam(+15)" , "671 All",
- "--guantanamo(+0)" , "53- All",
- "--guatemala(-1)" , "502 All",
- "--guatemala(0)" , "502 All",
- "--guyana(\t+2)" , "592 All",
- "--haiti(+0)" , "509 All",
- "--haiti(-3)" , "509 All",
- "--honduras(-1)" , "504 All",
- "--hong kong(+13)" , "852 All",
- "--iceland(+5)" , "354 All",
- "--india(\t+10)" , "242 All",
- "--indonesia(+12)" , "062 All",
- "--iran(\t+8)" , "98- All",
- "--iraq(+8)" , "964 All",
- "--ireland(+5)" , "353 Dublin",
- "--isreal(+7)" , "972 All",
- "--italy(+6)" , "39- Bologna, firenze, milano, padova, rome, tourin",
- "--ivory coast(+5)" , "225 All",
- "--japan(+14)" , "81- gyoda, nagoya, osaka, tokyo",
- "--jordan(+7)" , "431 All",
- "--kenya(+8)" , "254 All",
- "--korea(+14)" , "82- All",
- "--kuwait(+8)" , "965 All",
- "--lebenon(+7)" , "961 All",
- "--liberia(+5)" , "231 All",
- "--libya(+7)" , "218 All",
- "--liechtenstein(+6)" , "41- All-shared",
- "--luxembourg(+6)" , "352 All",
- "--malawi(+7)" , "265 All",
- "--malaysia(+13)" , "60- All",
- "--mexico(+1)" , "052 All",
- "--monaco(+6)" , "33- All-shared with France",
- "--morocco(+5)" , "212 All",
- "--netherlands antilles(+1)" , "599 All",
- "--netherlands(+6)" , "31- Amsterdam, badhoevedorp, rijswijk, zwolle",
- "--new caledonia(+16)" , "687 All",
- "--new zealand(+17)" , "64- Auckland, Wellington",
- "--nicaragua(-1)" , "505 All",
- "--nigeria(+6)" , "234 All",
- "--norway(+6)" , "47- Oslo",
- "--oman(+9)" , "968 All",
- "--pakistan(+10)" , "92- All",
- "--panama(+0)" , "507 All",
- "--paraguay(+1)" , "595 All",
- "--peru(+0)" , "51- All",
- "--phillipines(+13)" , "63- All",
- "--portugal(+5)" , "351 All",
- "--quatar(+9)" , "974 All",
- "--romania(+7)" , "40- All",
- "--saudia arabia(+8)" , "966 All",
- "--senegal(+5)" , "221 All",
- "--singapore(+13)" , "65- All",
- "--south africa(+7)" , "27- Johannesburg",
- "--spain(+6)" , "34- Barcelona, madrid",
- "--sri lanka(\t+10)" , "94- All",
- "--st denis" , "331 All",
- "--suriname(\t+1)" , "597 All",
- "--sweden(+6)" , "46- Gothenborg, malmoe, stockholm, basle, bern, lausanne, zurich",
- "--taiwan(+13)" , "886 All",
- "--thailand(+12)" , "66- All",
- "--tunisia(+6)" , "216 All",
- "--turkey(+8)" , "90- All",
- "--united arab emirates(+9)" , "971 arabia",
- "--united kingdom(+5)" , "44- birmingham, bristol, hounslow, leeds, london, \n manchester, middlesex, paisley",
- "--uruguay(+2)" , "598 All",
- "--vatican city(+2)" , "39- All-shared with Italy",
- "--venezuela(+1)" , "58- codata",
- "--yugoslavia(+6)" , "38- All",
- NULL } ;
-
- int i,j,found;
- unsigned k;
- char *t;
-
- found=0;
-
- if (x==2) /* a number area code */
- {
- for (i=0; area[i] != NULL; i++)
- if (strncmp(area[i],s,3)==0) /* test for match */
- {
- for (j=i-1; isdigit(*area[j]) ; --j) /* then go back for state */
- ;
- stprint(area[j]); /* special print out for state name */
- putchar('\n');
- printf(" %s.\n\n",area[i]);
- found=-1;
- }
- }
-
- else /* state name or two letter code is input */
- {
- for (i=0; s[i] != '\0'; i++) /* make everything lowercase */
- s[i]=tolower(s[i]);
- k=strlen(s);
- for (i=0; area[i] != NULL; i++)
- if (isdigit(*area[i])==0)
- if (strncmp(area[i]+2,s,k) == 0 ||
- (k==2 && strncmp(s,area[i],2)==0) || s[0]=='*')
- {
- found = -1;
- allprint(&area[i]);
- }
- }
- if (found==0)
- printf("Not found, %s.\n\n",s);
- } /* end areacode() */
-
- /* special printout for state name */
- stprint(s)
- char s[];
- {
- int i,n;
- putchar(toupper(s[0]));
- putchar(toupper(s[1]));
- printf(" ");
- putchar(toupper(s[2]));
- for (s+=3; *s != '\0' && *s != '(' ; s++)
- if (*s=='*')
- {
- putchar(' ');s++;
- putchar(toupper(*s));
- }
- else
- putchar(*s);
- if ((*s++)=='(')
- {
- printf(" (");
- i=(*s=='\t') ? 30 : 0;
- otime( tme[1]+satoi(s) , tme[2]+i );
- putchar(')');
- }
- printf(" area codes: ");
- } /* end stprint */
-
- /* print state and cities */
- allprint(area)
- char *area[];
- {
- int j;
- stprint(area[0]);
- putchar('\n');
- for (j=1; isdigit(*area[j]) ; j++)
- printf(" %s.\n",area[j]);
- putchar('\n');
- } /* end allprint() */
-
-
- /* integer convert to number */
- int satoi(s)
- char s[];
- {
- int i, n, sign;
-
- for (i=0; *s==' ' || *s=='\n' || *s=='\t'; s++)
- ; /* skip white space */
-
- sign = 1;
- if (*s == '+' || *s == '-')
- sign = (*s++ == '+') ? 1 : -1;
- for (n=0; *s >= '0' && *s <= '9'; s++)
- n = 10 * n + *s - '0';
- return(sign * n);
-
- } /* end satoi */
-
- /* limited string compare */
- int strncmp(x,y,n)
- char *x, *y;
- int n;
- {
- int c;
- while (n--) {
- if (c=*x-*y++) return (c);
- if (*x++=='\0') return (0);
- }
- return (0);
- }
-
- otime(h,m)
- int h,m;
- {
- static char s;
- while (m>60)
- {
- m-=60;
- h++;
- }
- s=( ((h+24)%24) < 12 ) ? 'a' : 'p';
- h=(h+23) %12 +1;
- printf("%02u:%02u %cm", h,m,s );
- } /* end otime */
-
- gettime(tme)
- int tme[];
- {
- int intno = 0x21; /* interrupt # */
- union REGS inregs; /* in reg */
- union REGS outregs; /* out reg */
-
- inregs.h.ah = 0x2C; /* svc # */
- int86(intno,&inregs,&outregs);
- tme[1] = outregs.h.ch; /* hrs */
- tme[2] = outregs.h.cl; /* min */
- tme[3] = outregs.h.dh; /* sec */
- tme[4] = outregs.h.dl; /* 100ths */
-
- inregs.h.ah = 0x2A; /* svc # */
- int86(intno,&inregs,&outregs);
- tme[5] = outregs.h.al; /* (0-6) (sun-sat) */
- tme[6] = outregs.x.cx; /* yr */
- tme[7] = outregs.h.dh; /* mo */
- tme[8] = outregs.h.dl; /* day */
- return;
- } /* end gettime() */
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int i,satoi();
- static char *dayno[] = {"Sun", "Mon", "Tue", "Wed", "Thurs", "Fri", "Sat"};
- puts(" ** Area Code Finder **");
- puts(" (C) Marty Smith 1983 - Changed 1/30/85 by DD");
- gettime(tme);
- printf(" ");
- otime(tme[1],tme[2]);
- printf(" %s %d/%d/%d\n\n", dayno[tme[5]], tme[7],tme[8],tme[6]);
- if (argc==1)
- {
- puts("Program searches for telephone area codes,");
- puts(" Use: AREA xxx xxx xxx ...\n");
- puts(" where xxx can be:");
- puts(" -An Area Code (like 914).");
- puts(" -A two letter state postal code (as in TX for Texas).");
- puts(" -The first few letters of the state name (as in MASS).");
- puts(" -A two word state names with * (as in New*Jersey).");
- puts(" -A foreign 2 digit area code with - (like 33- for France).");
- puts(" -A +n or -n for your timezone, relative to Eastern");
- puts(" (for example, Calif residents use 'AREA -3 ...').\n");
- puts(" Enter 'AREA *' for a list of all Area Codes.");
- }
-
- else
- for (i=1; i < argc; ++i)
- if (*argv[i]=='+' || *argv[i]=='-')
- tme[1]-=satoi(argv[i]);
- else
- if (isdigit(*argv[i])==0)
- areacode(argv[i],1);
- else
- areacode(argv[i],2);
-
- } /* end main() */